package com.youbug.mall.ware_wms.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class MyWmsMQConfig {

    @Bean
    public Exchange stockEventExchange(){
        TopicExchange exchange = new TopicExchange("stock-event-exchange",
                true, false);

        return exchange;
    }

    @Bean
    public Queue stockReleaseStockQueue(){
        Queue queue = new Queue("stock.release.stock.queue", true,
                false, false);

        return queue;
    }

    @Bean
    public Queue stockDelayQueue(){

        Map<String, Object> arguements = new HashMap<>();

        arguements.put("x-dead-letter-exchange", "stock-event-exchange");
        arguements.put("x-dead-letter-routing-key", "stock.release.order");
        arguements.put("x-message-ttl", 240*1000);

        Queue queue = new Queue("stock.delay.queue", true,
                false, false, arguements);

        return queue;
    }



    @Bean
    public Binding stockReleaseBinding(){

        Binding binding = new Binding("stock.release.stock.queue",
                Binding.DestinationType.QUEUE, "stock-event-exchange",
                "stock.release.#",null);

        return binding;
    }

    @Bean
    public Binding stockLockedBinding(){
        Binding binding = new Binding("stock.delay.queue",
                Binding.DestinationType.QUEUE, "stock-event-exchange",
                "stock.locked",null);

        return binding;
    }
}
